import urllib
import subprocess
import sys
import os

class NoFileFound(Exception):
    """Exception raised for errors in the file reading.

    Attributes:
        filename -- the name of the file
    """
    def __init__(self, filename):
        self.filename = filename
    def __str__(self):
        return `self.filename`

def check_files(files_list): 
    for file_name in files_list:        
        exists = os.path.isfile(file_name)
        if exists == False:
            raise NoFileFound(file_name)
        
    
def execute_binary( path):
    try:
        execution = subprocess.Popen( path, shell=True)
        execution.wait()

    except OSError, CalledProcessError:
        print '<<<<<<<<< Something whent wrong while executing >>>>>>>>>'

def get_macaddress():
    if sys.platform == 'win32':
        for line in os.popen("ipconfig /all"):
            if line.lstrip().startswith('Physical Address'):
                mac = line.split(':')[1].strip().replace('-',':')
                break
    else:
        for line in os.popen("/sbin/ifconfig"):
            if line.find('Ether') > -1:
                mac = line.split()[4]
                break
        return mac

def get_platform():
    return sys.platform
  
def download( url, filetowrite):
    f =  urllib.urlopen(url)
    g = f.read()
    file = open(filetowrite, "w")
    file.write(g)
    file.close()